

function ajax({ method, url, data }) {

    method = method ? method : "GET";

    return new Promise((resolve, reject) => {
        try {
            let xhr = new XMLHttpRequest();

            xhr.open(method, url);

            xhr.send(data ? data : null);

            xhr.onload = function () {
                if (this.status === 200 || this.status === 302) {
                    resolve(this.response);
                } else {
                    reject(this);
                }
            };
        } catch (error) {
            reject(error)
        }
    });
}

export default ajax

